package com.fz.test;

import com.ab.activity.BaseActivity;

import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;

public class TwoActivity extends BaseActivity implements OnTouchListener {
	private Button button1;
	private GestureDetector gestureDetector;
	private SoundPool pool;//������Ч
	private int sound;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_two);
		init();
	}

	private void init() {
		pool=new SoundPool(10, AudioManager.STREAM_SYSTEM, 5);
		sound=pool.load(this, R.raw.backeground, 1);
		button1=(Button) findViewById(R.id.button1);
		button1.setOnTouchListener(this);
		button1.setClickable(true);
		button1.setLongClickable(true);
		gestureDetector=new GestureDetector(this, new MyListener());
	}

	@Override
	public boolean onTouch(View arg0, MotionEvent arg1) {
		if(gestureDetector.onTouchEvent(arg1)){
			return true;
		}
		return false;
	}
	class MyListener extends  GestureDetector.SimpleOnGestureListener{

		@Override
		public boolean onDoubleTap(MotionEvent e) {
			Log.i("add", "onDoubleTap");
			return super.onDoubleTap(e);
		}

		@Override
		public boolean onDoubleTapEvent(MotionEvent e) {
			Log.i("add", "onDoubleTapEvent");
			return super.onDoubleTapEvent(e);
		}

		@Override
		public boolean onDown(MotionEvent e) {
			Log.i("add", "onDown");
			return super.onDown(e);
		}

		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
				float velocityY) {
			Log.i("add", "onFling");
			return super.onFling(e1, e2, velocityX, velocityY);
		}

		@Override
		public void onLongPress(MotionEvent e) {
			Log.i("add", "onLongPress");
			
			super.onLongPress(e);
		}

		@Override
		public boolean onScroll(MotionEvent e1, MotionEvent e2,
				float distanceX, float distanceY) {
			Log.i("add", "onScroll");
			pool.pause(sound);
			return super.onScroll(e1, e2, distanceX, distanceY);
		}

		@Override
		public void onShowPress(MotionEvent e) {
			Log.i("add", "onShowPress");
			super.onShowPress(e);
		}

		@Override
		public boolean onSingleTapConfirmed(MotionEvent e) {
			Log.i("add", "onSingleTapConfirmed");
			pool.play(sound, 1, 0, 0, 1, 1);
			return super.onSingleTapConfirmed(e);
		}

		@Override
		public boolean onSingleTapUp(MotionEvent e) {
			Log.i("add", "onSingleTapUp");
			return super.onSingleTapUp(e);
		}
		
	}

}
